<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>	
<script src="<?php echo URL::base() ?>media/js/jquery.json-2.4.js"></script>
<html>
<style>
.date{width:113.5px}	
.supplier{width:200px}
.purchaser{width:200px}
.table1 thead tr th,.table1 tbody th td{ border:1px solid #ffffff; vertical-align:middle;text-align:center;}
.form-horizontal .controls{ margin-left:90px;}
.form-horizontal .control-label{width:80px; display:inline-block;}
.form-horizontal .control-group{ }
.table-bordered th, .table-bordered td{border-left:1px solid #eeeeee; text-align:center; font-family:inherit;}
.asd{width:80px; text-align:right; display:inline-block; margin-right:4px;}
table tbody tr:nth-child(2n){ background-color:#f5f5f5;}

#detail_purchase {position: relative; margin: 30px auto; width: 1130px; height:500px; border: 3px solid #ccc; border-radius: 3px; box-shadow: 1px 1px 3px #666, 2px 2px 5px #333; overflow:hidden; z-index: 0;}
#ui-datepicker-div{z-index:40;}
#table {min-width: 1100px;background: #fff;}
table th .title,table td .data {width: 100%; max-width: 200px; white-space: nowrap; }
.theadFixed { position: absolute;}
</style>


<body>
    <div class="form-horizontal">
		<div style="margin-bottom:10px;">
			<span class="asd" for="input01">采购日期:</span>
      <input style="width:164px;" type="text" class="input-xlarge date"  id="date_from"  value="" readonly="true" />
			— <input style=" margin-right:10px;width:164px;" type="text" class="input-xlarge date"  id="date_to"  value="" readonly="true"/>
		</div>
	<div style="margin-bottom:10px;">
			<span class="asd" for="input01">付款日期:</span>
      <input style="width:164px;" type="text" class="input-xlarge date"  id="paydate_from"  value="" readonly="true" />
			— <input style=" margin-right:10px;width:164px;" type="text" class="input-xlarge date"  id="paydate_to"  value="" readonly="true"/>
		</div>
		<div style="margin-bottom:10px;">
				<span class="asd">供应商:</span>   
				<input style=" margin-right:10px;width:164px;" type="text" class="input-xlarge supplier"  id="supplier"  value=""/>
        </div>
																
	
		<div style="margin-bottom:10px;">
				<span class="asd" for="input01" >sku:</span>																	
        <input style=" width:164px; margin-right:10px;" type="text" class="input-xlarge sku"  name="" id="" value="" autocomplete="off"  />
    </div>
		<div style="margin-bottom:10px;">
			<span class="asd" >采购员:</span>
			<input type="text" class="input-xlarge purchaser" style="width:164px;"  name="" id="" value="">
			<button style="margin-left:10px;" class="btn btn-info" id="search_ids">查询</button>
			<button class="btn btn-inverse" onclick="resetdata()" type="button">重置</button>
			<button class="btn btn-success" id="download_ids">下载</button>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<button class="btn btn-success" id="downloading">下载<lable style="font-weight:bold;color:green">（含取消订单）</lable></button>
		</div>
		</div>
   </div>
<div id="detail_purchase" style="display:none;">
	<table id="table" class="table table-bordered table1" style=" border-collapse:collapse;width:100%;">
		<thead>
        <tr style=" background-color:#4EA392;color:#fff;">
				<th class="title"><div style="width:40px;">序号</div></th>
                <th class="title"><div style="width:70px;">采购员</div></th>
			<th class="title"><div style="width:90px;">采购日期</div></th>
			<th class="title"><div style="width:90px;">到货日期</div></th>

				<th class="title"><div style="width:70px;">采购单号</div></th>
				<th class="title"><div style="width:100px;">SKU</div></th>
				<th class="title"><div style="width:100px;">名称</div></th>

				<th class="title"><div style="width:150px;">供应商</div></th>
				<th class="title"><div style="width:80px;">数量</div></th>
                <th class="title"><div style="width:70px;">入库量</div></th>

				<th class="title"><div style="width:70px;">到货量</div></th>
				<th class="title"><div style="width:70px;">质检量</div></th>

                <th class="title"><div style="width:70px;">入库时间</div></th>
				<th class="title"><div style="width:70px;">未交量</div></th>
				<th class="title"><div style="width:70px;">超交量</div></th>
				<th class="title"><div style="width:70px;">状态</div></th>

				<!--<th class="title"><div style="width:105px;">付款时间</div></th>-->
			</tr>
		</thead>

			<tbody id="contents">
			</tbody>
		</table>
</div>
<table>
<th><div style="display:none" id="more"><button class="btn btn-info" id="more_ids">查看更多</button></div></th>
<th style="display:none" id="th_total">总计:</th><td><div id="total_quantity"></div></td>
</table>
</body>
</html>


<script>
	
$('#detail_purchase').mouseover(function(){
//alert(234);
	this.style.overflow = "scroll";

})
	
$('#detail_purchase').mouseout(function(){
	this.style.overflow = "hidden";
})


$('#detail_purchase').scroll (function(){
		
		if(this.scrollTop > 0)
			{
			//alert(123);
			
				$('#table > thead').addClass("theadFixed");
				$('#table > thead').css({'top':this.scrollTop + "px"});
				//$('#table > thead').css({'width':this.scrollTop + "px"});
			}
		else if(this.scrollTop <= 0)
			{
				$('#table > thead').removeClass("theadFixed");
			}
	})
</script>


<script>

var page =1;
//默认时间日期 查询条件
$(document).ready(function(){
	$("#ui-datepicker-div").css('z-index',40);
	$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
							$("#date_from").datepicker({
								//$("#ui-datepicker-div").css('z-index',40);  
							    onSelect:function(dateText,inst){ 
							       $("#date_to").datepicker("option","minDate",dateText);  
							    }  
							});  
							$("#date_to").datepicker({
								//$("#ui-datepicker-div").css('z-index',40);  
							    onSelect:function(dateText,inst){
							        $("#date_from").datepicker("option","maxDate",dateText);  
							    }  
							});
						$("#paydate_to").datepicker({
							
							    onSelect:function(dateText,inst){
							        $("#paydate_from").datepicker("option","maxDate",dateText);  
							    }  
							});
							$("#paydate_from").datepicker({
				
							    onSelect:function(dateText,inst){
							        $("#paydate_to").datepicker("option","minDate",dateText);  
							    }  
							});
	$("#status").val('<?php echo isset($status)?$status:"10"; ?>');
	//初始化checkbox的状态
	/*$("input[type='checkbox']").each(function(){
		if(this.checked){
			this.checked=false;
		}
	});*/
});

		//getClass
		var getByClass = function (oParent, sClass) {
			var aEle = oParent.getElementsByTagName("*");
			var re  = new RegExp("\\b"+sClass+"\\b", "i");
			var arr = [];

			for (var i = 0; i < aEle.length; i++) {
				if (re.test(aEle[i].className)) {
					arr.push(aEle[i]);
				}
			}
			return arr;
		}
//查询结果事件
	$("#search_ids").click(function(){
		var date_from = $("#date_from").val();
		var date_to   = $("#date_to").val();
		var paydate_from = $("#paydate_from").val();
		var paydate_to   = $("#paydate_to").val();

		var purchaser = $(".purchaser").val();
		var sku = $(".sku").val();
		var supplier = $("#supplier").val();
		
		
		$.ajax({
					type:'GET',
					dataType:"html",
					url:"<?php echo URL::site() ?>report/purchase/search",
					async:false,
					data:{
						'date_from':date_from,
						'date_to':date_to,
						'paydate_from':paydate_from,
						'paydate_to':paydate_to,
						'purchaser':purchaser,
						'sku':sku,
						'supplier':supplier
					},
					success:function(data){
						if(data==1)
						{$("#detail_purchase").hide();
							$("#more").hide();
						}else{
							page=1;
							$("#detail_purchase").show();
							$("#th_total").show();
							$("#contents").empty();
							$("#contents").html(data);
							$("#more").show();
						}
					}
				});
				$.ajax({
					type:'GET',
					dataType:"html",
					url:"<?php echo URL::site() ?>report/purchase/search_totals",
					async:false,
					data:{
						'date_from':date_from,
						'date_to':date_to,
						'paydate_from':paydate_from,
						'paydate_to':paydate_to,
						'purchaser':purchaser,
						'sku':sku,
						'supplier':supplier
					},
					success:function(data){
						$("#total_quantity").html(data);
					}
				});
				
				
				
				
				
				//$("#table > tbody").eq(0).find('tr').eq(0).find('td').css("background-color","#f00");
				
	
			

	});


	
	

					      //绑定未来事件
	$(document).on('click', '#more_ids', function(e){
			//alert($('.data0').html());
							      	  e.preventDefault(); 
												var date_from = $("#date_from").val();
												var date_to   = $("#date_to").val();
												var paydate_from = $("#paydate_from").val();
												var paydate_to   = $("#paydate_to").val();
												var supplier  = $("#supplier").val(); 
												var purchaser = $(".purchaser").val();
												var sku = $(".sku").val();
												page++;
												url = "<?php echo URL::base();?>report/purchase/search?date_from="+date_from+"&date_to="+date_to+"&supplier="+supplier+"&purchaser="+purchaser+"&sku="+sku+"&page="+page+"&paydate_from="+paydate_from+"&paydate_to="+paydate_to;
							            
							            if(url.length){
							            	get_pandian(url);
							            }
	});
//重置条件
function resetdata()
{
	$("#way").val(1);
	$("#date_from").val("");
	$("#date_to").val("");
	$("#paydate_from").val("");
	$("#paydate_to").val("");
	$("#supplier").val("");
	$(".sku").val("");
	$(".purchaser").val("");
}
function get_pandian(url){
	var dialog = art.dialog({title: '提示',icon:'question',lock: true});
	dialog.content('<p>数据查询中,请稍后...<p>');
	$.get(
    	 url,
    	   {

	    	 },
	    	 function(data){
				
	    	        //$('.mypage').clone().appendTo('#pager_links').show();
					if(data==1)
					{				
						$("#more").hide();
						dialog.close();
					}else{
 	    			dialog.close();
						$("#contents").append(data);
						$("#more").show();						
					}
	   	   }
    	 );
}
//下载
$("#download_ids").click(function(){
								var date_from = $("#date_from").val();
								var date_to   = $("#date_to").val();
								var paydate_from = $("#paydate_from").val();
								var paydate_to   = $("#paydate_to").val();
								var supplier  = $("#supplier").val(); 
								var purchaser = $(".purchaser").val();
								var sku = $(".sku").val();
								url = "date_from="+date_from+"&date_to="+date_to+"&supplier="+supplier+"&purchaser="+purchaser+"&sku="+sku+"&paydate_from="+paydate_from+"&paydate_to="+paydate_to;
								window.location.href="<?php echo URL::base()?>report/purchase/download?"+url;
							});
//添加含有取消状态订单的下载
$("#downloading").click(function(){
	var date_from = $("#date_from").val();
	var date_to   = $("#date_to").val();
	var paydate_from = $("#paydate_from").val();
	var paydate_to   = $("#paydate_to").val();
	var supplier  = $("#supplier").val(); 
	var purchaser = $(".purchaser").val();
	var sku = $(".sku").val();
	url = "date_from="+date_from+"&date_to="+date_to+"&supplier="+supplier+"&purchaser="+purchaser+"&sku="+sku+"&paydate_from="+paydate_from+"&paydate_to="+paydate_to;
	window.location.href="<?php echo URL::base()?>report/purchase/download?rem=1&"+url;
});
</script>

		
			
</script>
